﻿using System;

namespace MathService.NeuralNetworks
{
    public delegate double NeuralActivationFunction(double x);

    public static class ActivationFunctions
    {
        public static NeuralActivationFunction Threshold(double threshold)
        {
            return x => x > threshold ? 1 : (x == threshold ? .5 : 0);
        }

        public static NeuralActivationFunction Logistic(double tau)
        {
            return x => 1 / (1 + Math.Exp(-tau * x));
        }

        public static NeuralActivationFunction HyperbolycTan(double a)
        {
            return x =>
                       {
                           x *= a;
                           var exp = Math.Exp(x);
                           var exp_ = 1 / exp;
                           return (exp - exp_) / (exp + exp_);
                       };
        }
    }
}